package cn.kgc.itrip.search.controller;

import cn.kgc.itrip.beans.dto.Dto;
import cn.kgc.itrip.beans.vo.hotel.SearchHotCityVO;
import cn.kgc.itrip.beans.vo.hotel.SearchHotelVO;
import cn.kgc.itrip.search.entity.HotelSearchVO;
import cn.kgc.itrip.search.service.SearchHotelService;
import cn.kgc.itrip.utils.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/hotellist")
public class SearchHotelController {
    @Resource
    private SearchHotelService searchHotelService;

    /*酒店模块--酒店列表*/
    @RequestMapping(value="/searchItripHotelPage",method=RequestMethod.POST)
    public Dto doSearchItripHotelPage(@RequestBody SearchHotelVO vo){
        try{
            //表单验证
            if(EmptyUtils.isEmpty(vo.getDestination())){
                return DtoUtil.returnFail("目的地不能为空",ErrorCode.SEARCH_PARAMETER_ERROR);
            }

            Page<HotelSearchVO> page = new Page<>();
            page.setPageSize(vo.getPageSize()==null?Constants.DEFAULT_PAGE_SIZE:vo.getPageSize());
            page.setCurPage(vo.getPageNo()==null? Constants.DEFAULT_PAGE_NO:vo.getPageNo());

            searchHotelService.searchHotelListForPaging(page,vo);



            return DtoUtil.returnDataSuccess(page);
        }catch (Exception e){
            e.printStackTrace();
        return DtoUtil.returnFail("查询失败", ErrorCode.SEARCH_UNKNOWN);
        }
    }

/*酒店模块---首页推荐*/
    @RequestMapping(value = "/searchItripHotelListByHotCity",method = RequestMethod.POST)
    public Dto doSearchHotelListByHotCity(@RequestBody SearchHotCityVO vo) {

        try {
         //表单验证
            if(EmptyUtils.isEmpty(vo.getCityId())||EmptyUtils.isEmpty(vo.getCount())){
                return DtoUtil.returnFail("参数错误！",ErrorCode.SEARCH_PARAMETER_ERROR);
            }
            List<HotelSearchVO> voList=searchHotelService.searchHotelListByHotCity(vo);
            return DtoUtil.returnDataSuccess(voList);
        }catch (Exception e){
            e.printStackTrace();
        return DtoUtil.returnFail("查询失败", ErrorCode.SEARCH_UNKNOWN);
    }
    }
}
